package com.apes.fn.scm.used.model;


import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.product.model.Classify;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = UsedClassify.CONST_TABLE_NAME)
public class UsedClassify extends BaseModel {
    public static final String CONST_TABLE_NAME = "war_used_classify";


    @Id
    @Column(name = "id")
    @Comment("旧件分类")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "旧件", padding = 8)
    private String id;


    @Comment("旧件")
    @ManyToOne(optional = false)
    @JoinColumn(name = "used_id", referencedColumnName = "id", nullable=false)
    private Used used;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "classify_id", referencedColumnName = "id", nullable = false)
    @Comment("商品分类")
    private Classify classify;  //商品分类


    @Transient
    private String classifyName;

    public String getClassifyName() {
        if( classify == null ) return classify.getName();
        return classify.getName();
    }

}
